package selenium.other;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.io.File;
import java.io.IOException;

import static java.lang.Thread.sleep;

/**
 * @Author quan
 * @Description 截图
 * @Date 2023/5/18 11:29
 */
public class Demo3_CropScreen {
    public static void main(String[] args) throws IOException, InterruptedException {
        //1、创建驱动
        WebDriver webDriver = new ChromeDriver();
        //2、打开网址
        webDriver.get("https://www.baidu.com/");
        sleep(5000);
        //3、截图，获取截图文件file
        File file = ((TakesScreenshot)webDriver).getScreenshotAs(OutputType.FILE);
        //4、将file保存到电脑上的某个路径下
        FileUtils.copyFile(file,new File("C:\\Users\\权星\\Desktop\\crop.png"));
    }
}
